package com.yazi.mxz.person.controller.firm;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.myframework.smhj.common.tool.PageLink;
import com.myframework.smhj.hibernate.Page;
import com.myframework.smhj.hibernate.Searching;
import com.myframework.smhj.hibernate.Sort;
import com.yazi.mxz.common.entity.beans.MemberPrepaid;
import com.yazi.mxz.common.entity.custom.MemberPrepaid4Search;
import com.yazi.mxz.common.service.MemberPrepaidService;
import com.yazi.mxz.person.controller.MyPageLink;

@Controller("firm-memberPrepaidController")
@RequestMapping("/firm/memberPrepaid")
public class MemberPrepaidController extends BaseController {
	private static Logger log = LoggerFactory.getLogger(MemberPrepaidController.class);

	@Resource
	MemberPrepaidService memberPrepaidService;

	@RequestMapping("/list")
	public String list(MemberPrepaid4Search mp4s, Searching si, Model model) {
		debug(log, "充值记录查询");
		Page<MemberPrepaid> page;
		PageLink pl;
		try {
			
			// 只能查当前企业的充值会员
			mp4s.setCompany(getCompany());
			
			// 默认按加入时间倒序排序
			if (null == si.getSorts()) { 
				List<Sort> sorts = new ArrayList<Sort>();
				sorts.add(new Sort("addTime", true));
				si.setSorts(sorts);
			}
			
			page = memberPrepaidService.list(mp4s, si);
			pl = new MyPageLink(page.getPaging());
		} catch (Exception e) {
			error(log, e, "充值记录查询异常");
			return FORWARD_TIP;
		}

		model.addAttribute("list", page.getList());
		model.addAttribute("mp4s", mp4s);
		model.addAttribute("pl", pl);
		model.addAttribute("searchWord", si.getSearchWord());
		return "firm/memberPrepaid_list";
	}

}
